package org.helios.gwt.remote.sample.client;

import org.helios.gwt.remote.sample.client.shared.PortletHandle;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PortletBox extends Composite
{
	private Button closeButton;

	public PortletBox(String instanceId)
	{
		this.whereId = "p-" + instanceId;
		initWidget(createWidget());
	}
	
	public PortletHandle getHandle()
	{
		return handle;
	}
	
	public void setHandle(PortletHandle handle)
	{
		this.handle = handle;
	}
	
	private Widget createWidget()
	{
		VerticalPanel panel = new VerticalPanel();
		HorizontalPanel buttons = new HorizontalPanel();
		buttons.add(closeButton = new Button("X"));
		buttons.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		panel.add(buttons);
		panel.add(new HTMLPanel("<div id=\"" + whereId + "\"></div>"));
		return panel;
	}
	
	private String whereId;
	private PortletHandle handle;
	
	public String getWhereId()
	{
		return whereId;
	}

	public void addCloseHandler(ClickHandler handler) 
	{
		closeButton.addClickHandler(handler);
	}
}
